package com.earnings.okhttputils.utils.ui.activity.user;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.earnings.R;
import com.earnings.okhttputils.utils.OkHttp.OkHttpUtils;
import com.earnings.okhttputils.utils.UrlConstant.HttpUrl;
import com.earnings.okhttputils.utils.adapter.DataBindingBaseadapter;
import com.earnings.okhttputils.utils.bean.TreasureCountData;
import com.earnings.okhttputils.utils.bean.TreasureListData;
import com.earnings.okhttputils.utils.god.GodAdapter.GodBaseAdapter;
import com.earnings.okhttputils.utils.god.GodAdapter.GodViewHolder;
import com.earnings.okhttputils.utils.god.GodLeftHandBaseActivity;
import com.earnings.okhttputils.utils.https.HttpMap;
import com.earnings.okhttputils.utils.https.HttpObjectCallback;
import com.earnings.okhttputils.utils.utils.SwipeRefresh;
import com.earnings.okhttputils.utils.utils.TimestampTransform;

import java.util.ArrayList;
import java.util.Map;

/*
财币页面-我要直捐-累计直捐
 */

public class UserTreasureContributionRecordActivity extends GodLeftHandBaseActivity implements View.OnClickListener {


private RecyclerView recyclerView;
    private ArrayList<TreasureListData> datas;
    private GodBaseAdapter adapter;
private DataBindingBaseadapter dataBindingBaseadapter;
   
    @Override
    protected int onCreateLayoutId() {
        return R.layout.activity_user_treasure_contribution_record;
    }

    @Override
    protected void init() {

        setTitle("累计直捐");
        findViewById(R.id.sumbit).setOnClickListener(this);
        recyclerView= (RecyclerView) findViewById(R.id.recyclerview);
        inidData();
        //initData();
    }



    @Override
    public void onClick(View v) {

        int i = v.getId();
        if (i == R.id.sumbit) {
            finish();

        }
    }

    public void inidData(){
        datas=new ArrayList<>(  );
        adapter=new GodBaseAdapter<TreasureListData>(R.layout.item_treasure_list,datas) {
            @Override
            public void onBind(GodViewHolder holder, int position, TreasureListData data) {

               // holder.setText( mouth, data.getCreatetime().substring(0,7)   );
               // holder.setText( R.id.name, data.getTitle() );
                holder.setText( R.id.count, data.getRich() );
              //  holder.setText( R.id.info, data.getContent() );
                holder.setText( R.id.date, TimestampTransform.getYMD(  data.getCreatetime() ) );
             //   Glide.with( getContext() ).load( data.getImg() ).into( (ImageView) holder.getView( R.id.icon ) );
            }
        };

        new SwipeRefresh(this,0,R.id.recyclerview) {
            @Override
            public void pullDown() {
            }

            @Override
            public void pullUp() {
                page++;
                loadData();
            }
        };
        recyclerView.setLayoutManager( new LinearLayoutManager( this ) );
        recyclerView.setAdapter( adapter );
        showProgress();
        loadData();
    }

    int page=1;
    private void loadData() {
        Map map=new HttpMap( this );
        //  Calendar time = Calendar.getInstance();

        map.put( "p" ,page + "");
        //  map.put( "month" ,mouth+ "");
        OkHttpUtils.post().url( HttpUrl.USER_TURN_CAIBAO_LIST_URL).params(map).build().execute( new HttpObjectCallback<TreasureCountData>(this) {

            @Override
            public void onSuccess(TreasureCountData object, String msg) {


                    datas.addAll( object.getList() );

                setText(R.id.price,object.getTotal());
                adapter.notifyDataSetChanged();

                // treasureData.addAll( (ArrayList<TreasureListData>)object );
                // adatper.notifyDataSetChanged();
                dismissProgress();
            }

            @Override
            public void onFail(int code, String msg) {
                dismissProgress();

            }
        });

    }
}
